package lablayer.model.MathComponents;

import lablayer.model.ComponentFactory;
import lablayer.model.Componentable;
import lablayer.model.LabData;

/**
 *
 * @author Darkness
 */
class StandardDeviation implements MathComponent {
    private LabData result;

    private LabData data;

    private String componentName = "Среднее квадратичное отклонение";

    private String componentId = "3";

    public StandardDeviation() {
        super();
        this.result = new LabData();
    }

    @Override
    public LabData getData() {
        return this.data;
    }

    @Override
    public void calculate() {        
        Double value = 0.0;
                
        Componentable sampleVariance = ComponentFactory.createComponent(
            MathComponentFactory.createSampleVariance());
        sampleVariance.setData(this.data);
        sampleVariance.calculate();
        value = ((sampleVariance.getResult()).getData())[0][0][0];
        this.result = new LabData(LabData.parseString((new Double(Math.sqrt(value))).
            toString()));
    }

    @Override
    public void setData(LabData data) {
        try {
            assert data != null : "data is null pointer";
            this.data = data;
        } catch (Exception e) {
            //process exception here
        }
    }

    @Override
    public String getComponentId() {
        return this.componentId;
    }

    @Override
    public String getComponentName() {
        return this.componentName;
    }

    @Override
    public LabData getResult() {
        return this.result;
    }

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}
}
